﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
//using System.Web.Optimization;
using System.Web.Routing;
using System.Web.Security;
using BookExchange;
using BookExchange.Configuration;
using BookExchange.DAO;
using BookExchange.ODataService;

namespace BookExchange
{
    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            //BundleConfig.RegisterBundles(BundleTable.Bundles);
            //AuthConfig.RegisterOpenAuth();
            //RouteConfig.RegisterRoutes(RouteTable.Routes);

            BaseDao.database = new BookExchaneContext(new Uri(AppConfiguration.Instance.ODataSerivceUrl));
            BaseDao.database.Timeout = AppConfiguration.Instance.WebServiceTimeout;
            BaseDao.database.UsePostTunneling = true;
        }

        void Application_End(object sender, EventArgs e)
        {
            //  Code that runs on application shutdown

        }

        void Application_Error(object sender, EventArgs e)
        {
            ////write to file all errors
            //Exception ex = HttpContext.Current.Server.GetLastError();
            //var logPath = Path.Combine(Server.MapPath("logs"), "error.log");            
            //File.WriteAllText(logPath, string.Format("{0}{1} ___ {2}", Environment.NewLine, DateTime.Now, ex.ToString()));
            
            ////Redirect to error page
            //Response.Redirect("Error.aspx");
        }
    }
}
